﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DCTLib.Common;
using System.Data;

namespace DCTAccess.Business.Needs
{
    public class NeedController
    {
        public static bool Insert(Need objNeed)
        {
            return UpdateVallue(objNeed, StoreProceduAction.AddNew.ToString());
        }

        public static bool Update(Need objNeed)
        {
            return UpdateVallue(objNeed, StoreProceduAction.Update.ToString());
        }
       

        public static bool Delete(Need objNeed)
        {
            return UpdateVallue(objNeed, StoreProceduAction.Delete.ToString());
        }

        public static bool UpdateVallue(Need objNeed, string action)
        {
            SQLHelper sqlHelper = new SQLHelper();
            string sPro = "prNeeds";
            sqlHelper.AddParameter("@Action", action);
            sqlHelper.AddParameter("@NeedsID", objNeed.NeedID);
            sqlHelper.AddParameter("@NeedsName", objNeed.NeedName);
            //sqlHelper.AddParameter("@NeedsAlias", objNeed.NeedAlias);
            sqlHelper.AddParameter("@CategoryPageId", objNeed.CategoryPageId);
            sqlHelper.AddParameter("@IsEnable", objNeed.IsEnable);
            return sqlHelper.ExecuteSQL(sPro);
        }

        public static DataTable GetAll()
        {
            SQLHelper sqlHelper = new SQLHelper();
            string sProc = "Needs_GetAll";
            return sqlHelper.GetDataTable(sProc);
        }

        public static DataTable GetServices()
        {
            SQLHelper sqlHelper = new SQLHelper();
            string sProc = "Need_GetServices";
            return sqlHelper.GetDataTable(sProc);
        }

        //public static DataTable GetNeedByID(int id)
        //{
        //    SQLHelper sqlHelper = new SQLHelper();
        //    string sProc = "Needs_Get";
        //    sqlHelper.AddParameter("@NeedsID", id);
        //    return sqlHelper.GetDataTable(sProc);
        //}

        public static Need GetNeedByID(int needID)
        {
            SQLHelper sqlHelper = new SQLHelper();
            sqlHelper.CatchError = false;

            string sProc = "Needs_Get";
            sqlHelper.AddParameter("@NeedsID", needID);
            DataTable dtNeed = sqlHelper.GetDataTable(sProc);
            if (dtNeed.Rows.Count > 0)
            {
                Need objNeed = new Need();
                objNeed.NeedID = Convert.ToInt32(dtNeed.Rows[0]["NeedsID"].ToString());
                objNeed.NeedName = dtNeed.Rows[0]["NeedsName"].ToString();
                objNeed.NeedAlias = dtNeed.Rows[0]["NeedsAlias"].ToString();
                objNeed.CategoryPageId = Convert.ToInt32(dtNeed.Rows[0]["CategoryPageId"].ToString());
                objNeed.IsEnable = Convert.ToBoolean(dtNeed.Rows[0]["IsEnable"].ToString());
                return objNeed;
            }
            else
                return null;
        }
    }
}
